package com.cndym.servlet;

import java.io.IOException;
import java.util.*;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;

import com.cndym.cache.XMemcachedClientWrapper;
import com.cndym.service.IFillByYYService;
import com.cndym.utils.FillConfigUtils;
import com.cndym.utils.SpringUtils;

/**
 * @author faxc
 * @date 2014-12-25 上午10:50:06
 */
public class UploadTokenToMem extends HttpServlet
{
	 private Logger logger = Logger.getLogger(getClass());
	 XMemcachedClientWrapper memcachedClientWrapper = (XMemcachedClientWrapper) SpringUtils.getBean("xmemcachedClientWrapper");
	 IFillByYYService fillByYYService = (IFillByYYService) SpringUtils.getBean("fillByYYServiceImpl");
	 String sql="";  
	 String token_exp_minute= "";
	 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		 token_exp_minute=FillConfigUtils.getValue("TOKEN_EXP_MINUTE");
	    	sql="select * form usercode_token_mapping";
	    	List<Map<String,String>> list=fillByYYService.getListBySQL(sql);
	    	for(int i=0;i<list.size();i++)
	    	{
	    		memcachedClientWrapper.set(list.get(i).get("user_code"), 60*Integer.parseInt(token_exp_minute), list.get(i).get("token"));
	    		memcachedClientWrapper.set(list.get(i).get("token"), 60*Integer.parseInt(token_exp_minute), list.get(i).get("user_code"));
	    	}
	    }


	    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	        doGet(request, response);
	    }
	    
	    public static void main(String args[])
	    {
	   	 XMemcachedClientWrapper memcachedClientWrapper = (XMemcachedClientWrapper) SpringUtils.getBean("xmemcachedClientWrapper");
	    	memcachedClientWrapper.set("d7d46cd6007968d518b5ebc62d97bcca5efae3c0d3228ebf4f51739c0a766773db2aca8ec35e9836c311ee729eb5d5f3f86fbbdc954c1222", 60*Integer.parseInt("100"), "20141231113730163168");
	    }
}


